from pydub import AudioSegment
import os

# 设置FFmpeg路径
# ffmpeg_path = r"D:\FFmpeg\bin\ffmpeg.exe"
# AudioSegment.converter = ffmpeg_path

def m4a_to_wav(input_file, output_file):
    sound = AudioSegment.from_file(input_file, format="m4a")
    sound.export(output_file, format="wav")
    print("Conversion m4a_to_wav successful!")

def m4a_to_mp3(input_file, output_file):
    sound = AudioSegment.from_file(input_file, format="m4a")
    sound.export(output_file, format="mp3")
    print("Conversion m4a_to_mp3 successful!")

def webm_to_wav(input_file, output_file):
    # 读取 WebM 格式音频文件
    sound = AudioSegment.from_file(input_file, format="webm")
    # 将音频文件导出为 WAV 格式
    sound.export(output_file, format="wav")
    print("Conversion webm_to_wav successful!")

def webm_to_mp3(input_file, output_file):
    # 读取 WebM 格式音频文件
    sound = AudioSegment.from_file(input_file, format="webm")
    # 将音频文件导出为 WAV 格式
    sound.export(output_file, format="mp3")
    print("Conversion webm_to_mp3 successful!")

if __name__ == "__main__":
    input_file = r"D:\\WorkStation\\项目集\\youtube下载音视频\\audio\\Dan Kirsten   Electric Bass Color 6.webm"
    output_file = r"D:\\WorkStation\\项目集\\youtube下载音视频\\audio\\Dan Kirsten   Electric Bass Color 6.mp3"

    if os.path.exists(input_file):
        print("Input file exists!")
    else:
        print("Input file does not exist!")
    webm_to_mp3(input_file, output_file)
